﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

public enum ClipboardContentType { Text, File, Image };

public interface IClipboardContent
{
    ClipboardContentType ContentType { get; }
    string Content { get; }
	string FileName { get; set; }
	DateTime Date { get; set; }
    string Html {get; }
	string Id { get; set; }
}

public abstract class ClipboardContent : IClipboardContent
{
    public static IClipboardContent ParseClipboardContent(string type,string text)
    {
        try
        {
            IClipboardContent clipboardContent = null;
            ClipboardContentType contentType = (ClipboardContentType)Enum.Parse(typeof(ClipboardContentType), type);
            switch(contentType)
            {
                case ClipboardContentType.Text:
                    clipboardContent = new TextClipboardContent(text);
                    break;
                case ClipboardContentType.File:
                    clipboardContent = new FileClipboardContent(text);
                    break;
                case ClipboardContentType.Image:
                    clipboardContent = new ImageClipboardContent(text);
					break;
                default:
                    return null;
            }

            return clipboardContent;
        }
        catch
        {
            return null;
        }
    }

	public ClipboardContent()
	{
		id = System.Guid.NewGuid().ToString().Replace("-","");
	}

	protected string id;

	public virtual string FileName { get; set; }
	public virtual DateTime Date { get; set; }

    public virtual ClipboardContentType ContentType
    {
        get
        {
            return ClipboardContentType.Text;
        }
    }

	public string Id
	{
		get
		{
			return id;
		}
		set
		{
			id = value;
		}
	}


    public virtual string Content
    {
        get
        {
            return "";
        }
    }

    public virtual string Html
    {
		get
		{
			return String.Format("<xmp>{0}</xmp>",Content); // Content.Replace(Environment.NewLine, "<br/>").Replace(" ", "&nbsp;").Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace("&", "&amp;");
		}
    }

    public override string ToString()
    {
        return Html;
    }
}

public class TextClipboardContent : ClipboardContent
{
    public string Text { get; set; }

    public TextClipboardContent() : base()
    {
        
    }

    public TextClipboardContent(string text) : this()
    {
        Text = text;
    }

    public override ClipboardContentType ContentType
    {
        get
        {
            return ClipboardContentType.Text;
        }
    }

    public override string Content
    {
        get
        {
            return Text;
        }
    } 
}

public class FileClipboardContent : ClipboardContent
{
    public string File { get; set; }

    public FileClipboardContent() : base()
    {

    }

    public FileClipboardContent(string file) : this()
    {
        File = file;
    }

    public override ClipboardContentType ContentType
    {
        get
        {
            return ClipboardContentType.File;
        }
    }

    public override string Content
    {
        get
        {
			return File;
        }
    }

	public override string Html
	{
		get
		{
			return String.Format("<img alt=\"chain\" src=\"../images/attachment.png\" /> <a href=\"{0}\">{1}</a>", File.Replace("~/Clipboard/", ""), Path.GetFileName(File));
		}
	}
}

public class ImageClipboardContent : ClipboardContent
{
	public string File { get; set; }

    public ImageClipboardContent() : base()
    {

    }

	public ImageClipboardContent(string file) : this()
	{
		File = file;
	}

    public override ClipboardContentType ContentType
    {
        get
        {
            return ClipboardContentType.Image;
        }
    }

	public override string Content
	{
		get
		{
			return File;
		}
	}

	public override string Html
	{
		get
		{
			return String.Format("<img alt=\"\" class=\"thumbnail\" src=\"{0}\" /> <a href=\"{0}\">{1}</a>", File.Replace("~/Clipboard/", ""), Path.GetFileName(File));
		}
	}
}